package com.sxjh.service.impl;

import com.sxjh.common.Constant;
import com.sxjh.entity.Ic;
import com.sxjh.entity.IcLog;
import com.sxjh.entity.WagonNumber;
import com.sxjh.mapper.IcLogMapper;
import com.sxjh.service.IcLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sxjh.service.IcService;
import com.sxjh.service.WagonNumberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

/**
 * <p>
 * IC卡历史记录  服务实现类
 * </p>
 *
 * @author zixin
 * @since 2021-06-07
 */
@Service
public class IcLogServiceImpl extends ServiceImpl<IcLogMapper, IcLog> implements IcLogService {

  @Autowired
  private IcService icService;

  @Autowired
  private WagonNumberService wagonNumberService;

  @Override
  public void saveLog(Integer vehId, Integer icId, String img1, String img2, Integer type) {
    Ic ic = icService.getById(icId);
    WagonNumber wagonNumber = wagonNumberService.getById(vehId);
    IcLog icLog = new IcLog();
    icLog.setIcNumber(ic.getNumber());
    icLog.setVehNumber(wagonNumber.getNumber());
    icLog.setType(type);
    if (type == Constant.UNLOAD_EMPTY) {
      icLog.setTareImg(img1);
      icLog.setTareImgTwo(img2);
    }
    if (type == Constant.UNLOAD_WEIGHT) {
      icLog.setRoughImg(img1);
      icLog.setRoughImgTwo(img2);
    }
    save(icLog);
  }

  @Override
  @Async(value = "taskExecutor")
  public void saveLog(Integer vehId, String icNumber, String weight, String img1, String img2, Integer type) {
    WagonNumber wagonNumber = wagonNumberService.getById(vehId);
    IcLog icLog = new IcLog();
    icLog.setIcNumber(icNumber);
    icLog.setVehNumber(wagonNumber.getNumber());
    icLog.setType(type);
    if (type == Constant.UNLOAD_EMPTY) {
      icLog.setTareImg(img1);
      icLog.setTareImgTwo(img2);
      icLog.setTare(weight);
    }
    if (type == Constant.UNLOAD_WEIGHT) {
      icLog.setRoughImg(img1);
      icLog.setRoughImgTwo(img2);
      icLog.setRough(weight);
    }
    save(icLog);
  }
}
